<template>
  <div>
    <el-form ref="formRef" :model="formData" label-width="100px">
      <el-form-item label="姓名">
        <el-input v-model="formData.name"></el-input>
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="formData.age"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="formData.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { ElForm } from 'element-plus';
import { reactive } from 'vue';
import { useCompRef } from './useInsRef';

const formData = reactive({
  name: '',
  age: '',
  address: '',
})

// 官方文档 defineComponent 那里也有说
const formRef = useCompRef(ElForm)

const onSubmit = () => {
  console.log(formData)
  formRef.value?.validate
}

</script>

<style scoped>

</style>